<!--
 * @Author: wangding
 * @Date: 2020-11-06 15:46:12
 * @LastEditTime: 2021-01-26 19:14:33
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \solaxcloud\src\views\overview-inverter\alarm\details.vue
-->
<template>
    <div>
        <el-dialog
        :title="$t('Error_detail')"
        :visible="visibleInfo"
        @opened="()=>{getDetailAlarmPage()}"
        width="900px"
        @close="close"
        >
            <div class="search-box">
                <span>{{$t('alarm.date')}}：</span>
                <el-date-picker
                v-model="startTime"
                type="date"
                :placeholder="$t('selectDate')"
                value-format='yyyy-MM-dd'
                :clearable='false'
                :picker-options="pickerOptions"
                >
                </el-date-picker>
                <span>-</span>
                <el-date-picker
                v-model="endTime"
                type="date"
                :placeholder="$t('selectDate')"
                value-format='yyyy-MM-dd'
                :clearable='false'
                :picker-options="pickerOptions"
                >
                </el-date-picker>
                <el-button type="primary" @click="query" style='margin-left:10px;'>{{$t('query')}}</el-button>
            </div>
            <div class="content-box clearfix">
                <baseTable v-loading="loading"  row-key='sid' :data="dataRows" border  stripe   :column='column' :select='false'>
                    <template #errorType="{data}">
                        {{UtilsFun.getValueByCode(alarmTypes,data.errorType)}}
                    </template>
                </baseTable>
                <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="current"
                :page-sizes="[10, 20, 30, 50]"
                :page-size="size"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total">
                </el-pagination>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import moment from 'moment'
import baseTable from '@/components/common/baseTable'
export default {
    components: {
        baseTable
    },
    props: {
        inverterSn:{
            type:String,
            default:() =>{return ''}
        },
        alarmTypes:{
            type:Array,
            default:() =>{return []}
        }
    },
    data() {
        return {
            startTime:moment(new Date()).subtract(1,'months').format('YYYY-MM-DD'),
            endTime:moment().format("YYYY-MM-DD"),
            pickerOptions:{ //禁用今天之后的时间
                disabledDate(time) {
                    return time.getTime() > Date.now()
                }
            },
            size:10,
            current:1,
            total:1,
            loading:false,
            dataRows:[],
            column:[{
            //     title: this.$t('devWifi.wifiSN'),
            //     value: 'wsn',
            //     slot: 'wsn'
            // },{
            //     title:  this.$t('device.inverter.SN'),
            //     value: 'inverterSn'
            // },{
            //     title: this.$t('user.loginName'),
            //     value: 'loginName'
            // },{
                title: this.$t('alarm.errorType'),
                value: 'errorType',
                slot: 'errorType'
            },{
                title: this.$t('alarm.errorMessage'),
                value: 'errorMessage'
            },{
                title: this.$t('test.deviceTest.inverterAlarm.happenTime'),
                value: 'reportStartTime'
            },{
                title: this.$t('recovery.Time.new'),
                value: 'recoveryTime'
            }],
            typeList:[]
        };
    },
    computed: {
        visibleInfo(){
            return this.$store.state.sysStore.visibleInfo
        }
    },
    watch: {

    },
    created() {

    },
    mounted() {
    },
    methods: {
        close(){
            this.startTime = moment(new Date()).subtract(1,'months').format('YYYY-MM-DD');
            this.endTime = moment().format("YYYY-MM-DD"),
            this.dataRows=[]
            this.size = 10
            this.current = 1
            this.total = 1
            this.$store.commit('setVisibleInfo',false)
        },
        initPage(){
            this.getDetailAlarmPage()
        },
        query(){
            this.current = 1
            this.getDetailAlarmPage()
        },
        async getDetailAlarmPage(){
            this.loading = true
            let res = await this.API.devalarmhandlerecordGetDetailAlarmPage({
                inverterSn:this.inverterSn,
                startTime:this.startTime,
                endTime:this.endTime,
                size:this.size,
                current:this.current,
            })
            this.loading = false
            this.dataRows = res.rows
            this.total = res.total
        },
        returnTypeCode(val){
           let code = ''
           this.typeList.forEach(item =>{
               if(item.value == val){
                   code = item.code
               }
           })
           return code
        },
        handleCurrentChange(val) {
          this.current = val
          this.getDetailAlarmPage()
        },
        handleSizeChange(val) {
          this.size = val
          this.current = 1
          this.getDetailAlarmPage()
        }
    },
};
</script>

<style  lang="less" scoped>
</style>
